package com.sky.mapper;

import com.sky.dto.GoodsSalesDTO;
import com.sky.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderDetailMapper {

    /**
     * 订单详情表批量插入数据
     * @param orderDetails
     */
    void insertBatch(List<OrderDetail> orderDetails);

    /**
     * 根据订单id查询订单详情
     * @param id
     * @return
     */
    @Select("select * from order_detail where order_id = #{id}")
    List<OrderDetail> getByOrderId(Long id);

    /**
     * 获取商品销售情况
     * 查询order_detail表，根据dish_id或者setmeal_id分组，统计每个菜品或者套餐的数量,取销量前10的name
     */
    @Select("select name, sum(number) as total from order_detail group by name order by total desc limit 10")
    List<GoodsSalesDTO> getGoodSale();
}
